package com.example.webflux.controller;

import com.example.webflux.model.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangdj
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("")
    public User getUser() {
        User user = new User();
        user.setId(1L);
        user.setName("张三");
        return user;
    }

    @GetMapping("/list")
    public List<User> getUserList() {
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setId(1L);
        user.setName("张三");
        users.add(user);
        users.add(user);
        return users;
    }

    @GetMapping("/{id}")
    public String getUrlParam(@PathVariable("id") Long id) {
        return id + "";
    }

    @PostMapping("")
    public User jsonUser(@RequestBody User user) {
        return user;
    }

    @PostMapping("/form")
    public User formUser(User user) {
        return user;
    }

    @GetMapping("timeout")
    public String timeout() throws InterruptedException {
        System.out.println(System.currentTimeMillis() + "----------------");
        Thread.sleep(5 * 1000);
        return "123sdf";
    }
}
